// $Id$
// Interface of EventManager class
//
// ml278
// Copyright (C) 2008 Bjørn Øivind Bjørnsen, Aleksander Gjermundsen, Knut Andre Tidemann, Thomas Hansen
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

#ifndef __EVENTMANAGER_H
#define __EVENTMANAGER_H

#include "Ogre.h"
#include "OgreSingleton.h"

#include <vector>

#include "eventlistener.h"

using namespace Ogre;
using namespace std;

namespace ml278 
{
	// forward declaration
	class EventListener;
	
	/// contains list of events to be processed, supports strict ordering
	class EventManager : public Singleton<EventManager>, public FrameListener
	{
	public:
		EventManager();
		~EventManager();
		
		bool frameStarted(const FrameEvent &evt);
		bool frameEnded(const FrameEvent &evt);
		
		/// adds events at the back of the vector
		void addEventListener(EventListener *listener);
		/// adds event at the specified position (linear time, use with caution)
		void addEventListener(EventListener *listener, unsigned int position);
		
		/// remove specified eventlistener
		bool removeEventListener(EventListener *listener);
		
		const unsigned int getTotalNumberOfListeners() const
		{
			return(mTotalNumListeners);
		}
		
		const unsigned int getNumberOfListeners(EventType t) const
		{
			return(mNumListeners.at(t));
		}
	private:
		// contains all listeners of different types
		vector<vector<EventListener*> > mListeners;
		// total number of listeners
		unsigned int mTotalNumListeners;
		vector<unsigned int> mNumListeners;
	};
}

#endif //#ifndef __EVENTMANAGER_H
